package design.pattern.application.CommandAndChain;

import java.util.ArrayList;
import java.util.List;

/**
 * @program JavaBase
 * @description:
 * @author: zhanglu
 * @create: 2020-05-22 14:35:00
 */
public abstract class Command {

    public abstract String execute(CommandVo vo);
    //建立链表
    protected final List<? extends CommandName> buildChain(Class<? extends  CommandName> abstractClass){
        //取出所有的命令名下的子类
        List<Class> classes = ClassUtils.getSonClass(abstractClass);
        //存放命令的实例，并建立链表关系
        List<CommandName> commandNameList = new ArrayList<>();
        for (Class c : classes) {
            CommandName commandName = null;
            try {
                commandName = (CommandName) Class.forName(c.getName()).newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }
            commandNameList.add(commandName);
        }
        return commandNameList;
    }

}
